//
//  OSCNews.m
//  oschina_song
//
//  Created by song on 16/1/27.
//  Copyright © 2016年 song. All rights reserved.
//

#import "OSCNews.h"
#import "NSDate+Util.h"

@interface OSCNews()


@end

static NSString * const kID = @"id";
static NSString * const kTitle = @"title";
static NSString * const kBody = @"body";
static NSString * const kCommentCount = @"commentCount";
static NSString * const kAuthor = @"author";
static NSString * const kAuthorID = @"authorid";
static NSString * const kPubDate = @"pubDate";
static NSString * const kNewsType = @"newstype";
static NSString * const kType = @"type";
static NSString * const kAttachment = @"attachment";
static NSString * const kAuthorUID2 = @"authoruid2";


@implementation OSCNews

-(id)initWithXML:(ONOXMLElement *)xml
{
    if(self = [super init])
    {
        _newsID =[[[xml firstChildWithTag:kID] numberValue] longLongValue];
        _title = [[xml firstChildWithTag:kTitle] stringValue];
        _body = [[xml firstChildWithTag:kBody] stringValue];
        _authorID =[[xml firstChildWithTag:kAuthorID] numberValue];
        
        _author = [[xml firstChildWithTag:kAuthor] stringValue];
        _commentCount = [[xml firstChildWithTag:kCommentCount] numberValue];
        _pubDate = [NSDate dateFromString:  [[xml firstChildWithTag:kPubDate] stringValue]];
        
        ONOXMLElement *newsType = [xml firstChildWithTag:kNewsType];
        _type = [[[newsType firstChildWithTag:kType] numberValue] intValue];
        _attachment = [[newsType firstChildWithTag:kAttachment] stringValue];
        _authorUID2 = [[[newsType firstChildWithTag:kAuthorUID2] numberValue] longLongValue];
        _eventURL = [NSURL URLWithString:[[[newsType firstChildWithTag:@"eventurl"] stringValue]
                                          stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
        _url = [NSURL URLWithString:[[[xml firstChildWithTag:@"url"] stringValue]
                                     stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
    }
    
    return  self;
}


@end
